GdkWindowObject *private = (GdkWindowObject *)window;
GdkEvent *event;
- private->x = content_rect.origin.x;
- private->y = _gdk_quartz_window_get_inverted_screen_y (content_rect.origin.y + content_rect.size.height);
+ _gdk_quartz_window_xy_to_gdk_xy (content_rect.origin.x,
+ content_rect.origin.y + content_rect.size.height,
+ &private->x, &private->y);
/* Synthesize a configure event */
event = gdk_event_new (GDK_CONFIGURE);
_gdk_event_queue_append (gdk_display_get_default (), event);
}
--(id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
+-(id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag screen:(NSScreen *)screen
{
self = [super initWithContentRect:contentRect
styleMask:styleMask
backing:backingType
- defer:flag];
+ defer:flag
+ screen:screen];
[self setAcceptsMouseMovedEvents:YES];
[self setDelegate:self];
NSPoint point = [sender draggingLocation];
NSPoint screen_point = [self convertBaseToScreen:point];
GdkEvent event;
+ int gx, gy;
update_context_from_dragging_info (sender);
+ _gdk_quartz_window_nspoint_to_gdk_xy (screen_point, &gx, &gy);
event.dnd.type = GDK_DRAG_MOTION;
event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
event.dnd.send_event = FALSE;
event.dnd.context = current_context;
event.dnd.time = GDK_CURRENT_TIME;
- event.dnd.x_root = screen_point.x;
- event.dnd.y_root = _gdk_quartz_window_get_inverted_screen_y (screen_point.y);
+ event.dnd.x_root = gx;
+ event.dnd.y_root = gy;
(*_gdk_event_func) (&event, _gdk_event_data);
NSPoint point = [sender draggingLocation];
NSPoint screen_point = [self convertBaseToScreen:point];
GdkEvent event;
+ int gy, gx;
update_context_from_dragging_info (sender);
+ _gdk_quartz_window_nspoint_to_gdk_xy (screen_point, &gx, &gy);
event.dnd.type = GDK_DROP_START;
event.dnd.window = g_object_ref ([[self contentView] gdkWindow]);
event.dnd.send_event = FALSE;
event.dnd.context = current_context;
event.dnd.time = GDK_CURRENT_TIME;
- event.dnd.x_root = screen_point.x;
- event.dnd.y_root = _gdk_quartz_window_get_inverted_screen_y (screen_point.y);
+ event.dnd.x_root = gx;
+ event.dnd.y_root = gy;
(*_gdk_event_func) (&event, _gdk_event_data);
#include "gdk.h"
#include "gdkwindowimpl.h"
#include "gdkprivate-quartz.h"
+#include "gdkscreen-quartz.h"
#include "gdkinputprivate.h"
static gpointer parent_class;
{
GdkWindowObject *private = GDK_WINDOW_OBJECT (window);
gint x, y;
+ gint gx, gy;
GdkWindow *toplevel;
gint tx, ty;
static NSWindow *debug_window[10];
x += tx;
y += ty;
- rect = NSMakeRect (x,
- _gdk_quartz_window_get_inverted_screen_y (y + private->height),
- private->width, private->height);
+ _gdk_quartz_window_gdk_xy_to_xy (x, y + private->height,
+ &gx, &gy);
+
+ rect = NSMakeRect (gx, gy, private->width, private->height);
if (debug_window[number] && NSEqualRects (rect, old_rect[number]))
return;
gdk_window_get_parent (window)));
}
-/* FIXME: It would be nice to have one function that takes an NSPoint
- * and flips the coords for any window.
- */
-gint
-_gdk_quartz_window_get_inverted_screen_y (gint y)
+
+void
+_gdk_quartz_window_gdk_xy_to_xy (gint gdk_x,
+ gint gdk_y,
+ gint *ns_x,
+ gint *ns_y)
+{
+ GdkScreenQuartz *screen_quartz = GDK_SCREEN_QUARTZ (_gdk_screen);
+
+ if (ns_y)
+ *ns_y = screen_quartz->height - gdk_y + screen_quartz->min_y;
+
+ if (ns_x)
+ *ns_x = gdk_x + screen_quartz->min_x;
+}
+
+void
+_gdk_quartz_window_xy_to_gdk_xy (gint ns_x,
+ gint ns_y,
+ gint *gdk_x,
+ gint *gdk_y)
{
- int index;
- GdkRectangle gdk_rect;
- NSScreen *main_screen = [NSScreen mainScreen];
- NSRect rect = [main_screen frame];
+ GdkScreenQuartz *screen_quartz = GDK_SCREEN_QUARTZ (_gdk_screen);
- index = [[NSScreen screens] indexOfObject:main_screen];
+ if (gdk_y)
+ *gdk_y = screen_quartz->height - ns_y + screen_quartz->min_y;
- gdk_screen_get_monitor_geometry (_gdk_screen, index, &gdk_rect);
+ if (gdk_x)
+ *gdk_x = ns_x - screen_quartz->min_x;
+}
- return gdk_rect.height - y + rect.origin.y + gdk_rect.y;
+void
+_gdk_quartz_window_nspoint_to_gdk_xy (NSPoint point,
+ gint *x,
+ gint *y)
+{
+ _gdk_quartz_window_xy_to_gdk_xy (point.x, point.y,
+ x, y);
}
static GdkWindow *
screen_point = [NSEvent mouseLocation];
- x_root = screen_point.x;
- y_root = _gdk_quartz_window_get_inverted_screen_y (screen_point.y);
+ _gdk_quartz_window_nspoint_to_gdk_xy (screen_point, &x_root, &y_root);
point = [nswindow convertScreenToBase:screen_point];
clear_toplevel_order ();
}
+static NSScreen *
+get_nsscreen_for_x (gint x)
+{
+ int i;
+ NSArray *screens;
+
+ GDK_QUARTZ_ALLOC_POOL;
+
+ screens = [NSScreen screens];
+
+ for (i = 0; i < [screens count]; i++)
+ {
+ NSRect rect = [[screens objectAtIndex:i] frame];
+
+ /* FIXME: Only horizontal layouts supported for now. Also
+ * see comments in gdkscreen-quartz.c
+ */
+ if (x >= rect.origin.x && x <= rect.origin.x + rect.size.width)
+ return [screens objectAtIndex:i];
+ }
+
+ GDK_QUARTZ_RELEASE_POOL;
+
+ return NULL;
+}
+
void
_gdk_window_impl_new (GdkWindow *window,
GdkWindow *real_parent,
case GDK_WINDOW_DIALOG:
case GDK_WINDOW_TEMP:
{
+ NSScreen *screen;
+ NSRect screen_rect;
NSRect content_rect;
int style_mask;
+ int nx, ny;
const char *title;
- content_rect = NSMakeRect (private->x,
- _gdk_quartz_window_get_inverted_screen_y (private->y) - private->height,
+ /* initWithContentRect will place on the mainScreen by default.
+ * We want to select the screen to place on ourselves. We need
+ * to find the screen the window will be on and correct the
+ * content_rect coordinates to be relative to that screen.
+ */
+ _gdk_quartz_window_gdk_xy_to_xy (private->x, private->y, &nx, &ny);
+
+ screen = get_nsscreen_for_x (nx);
+ screen_rect = [screen frame];
+ nx -= screen_rect.origin.x;
+ ny -= screen_rect.origin.y;
+
+ content_rect = NSMakeRect (nx, ny - private->height,
private->width,
private->height);
impl->toplevel = [[GdkQuartzWindow alloc] initWithContentRect:content_rect
styleMask:style_mask
backing:NSBackingStoreBuffered
- defer:NO];
+ defer:NO
+ screen:screen];
if (attributes_mask & GDK_WA_TITLE)
title = attributes->title;
{
NSRect content_rect;
NSRect frame_rect;
+ gint gx, gy;
- content_rect = NSMakeRect (private->x,
- _gdk_quartz_window_get_inverted_screen_y (private->y + private->height),
- private->width, private->height);
+ _gdk_quartz_window_gdk_xy_to_xy (private->x, private->y + private->height,
+ &gx, &gy);
+
+ content_rect = NSMakeRect (gx, gy, private->width, private->height);
frame_rect = [impl->toplevel frameRectForContentRect:content_rect];
[impl->toplevel setFrame:frame_rect display:YES];
*/
if ([impl->toplevel styleMask] == NSBorderlessWindowMask)
{
- if (x)
- *x = ns_rect.origin.x;
- if (y)
- *y = _gdk_quartz_window_get_inverted_screen_y (ns_rect.origin.y + ns_rect.size.height);
+ _gdk_quartz_window_xy_to_gdk_xy (ns_rect.origin.x,
+ ns_rect.origin.y + ns_rect.size.height,
+ x, y);
}
else
{
content_rect = [impl->toplevel contentRectForFrameRect:[impl->toplevel frame]];
- tmp_x = x + content_rect.origin.x;
- tmp_y = y + _gdk_quartz_window_get_inverted_screen_y (content_rect.origin.y + content_rect.size.height);
+ _gdk_quartz_window_xy_to_gdk_xy (content_rect.origin.x,
+ content_rect.origin.y + content_rect.size.height,
+ &tmp_x, &tmp_y);
+
+ tmp_x += x;
+ tmp_y += y;
while (private != GDK_WINDOW_OBJECT (toplevel))
{
if (window == _gdk_root)
{
point = [NSEvent mouseLocation];
- x_tmp = point.x;
- y_tmp = _gdk_quartz_window_get_inverted_screen_y (point.y);
+ _gdk_quartz_window_nspoint_to_gdk_xy (point, &x_tmp, &y_tmp);
}
else
{
ns_rect = [impl->toplevel frame];
- rect->x = ns_rect.origin.x;
- rect->y = _gdk_quartz_window_get_inverted_screen_y (ns_rect.origin.y + ns_rect.size.height);
+ _gdk_quartz_window_xy_to_gdk_xy (ns_rect.origin.x,
+ ns_rect.origin.y + ns_rect.size.height,
+ &rect->x, &rect->y);
+
rect->width = ns_rect.size.width;
rect->height = ns_rect.size.height;
}